package com.caidan.diagram.controller;

import com.caidan.diagram.common.Result;
import com.caidan.diagram.domain.dto.FigureUserLoginDTO;
import com.caidan.diagram.domain.dto.FigureUserRegisterDTO;
import com.caidan.diagram.service.FigureUserService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/figureuser")
@Slf4j
@AllArgsConstructor
public class FigureUserController {
    private final FigureUserService figureUserService;

    @PostMapping("/register")
    public Result register(@RequestBody FigureUserRegisterDTO figureUserRegisterDTO, HttpServletRequest httpServletRequest){
        if(figureUserRegisterDTO == null){
            return Result.fail("注册信息有误");
        }
        return figureUserService.registerUser(figureUserRegisterDTO, httpServletRequest);
    }
    @PostMapping("/login")
    public Result login(@RequestBody FigureUserLoginDTO figureUserLoginDTO, HttpServletRequest httpServletRequest){
        if(figureUserLoginDTO == null){
            return Result.fail("登录信息有误");
        }
        return figureUserService.login(figureUserLoginDTO, httpServletRequest);
    }
}
